package com.document;

import cn.hutool.core.io.FileUtil;

import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public class TxtToHtml {

    public static void main(String[] args) throws IOException {
         String s = "C:\\Users\\竹子\\Desktop\\示例数据\\世界末日现场！以色列军队撕开天地，开启加沙巷战地狱！.txt";
        String title = FileUtil.mainName(s);
        System.out.println(title);
         //         txtToHtml(s,"C:\\Users\\竹子\\Desktop\\示例数据\\tt.html");
    }
    public static void txtToHtml(String sourcePath, String path) throws IOException {
        Path filepath = Paths.get(sourcePath);
        List<String> lines = Files.readAllLines(filepath);
        String className = "";
        String html = "";
        String lineSpan = "";
        int i=0;
        for(String lineStr:lines){
            className  ="line"+i;
            lineSpan="<p class=\""+className+"\">"+lineStr+"</p> \n" ;
            html+=lineSpan;
            i++;
        }
//        System.out.println(html);
        try (FileWriter fileWriter = new FileWriter(path)) {
            fileWriter.append(html);
        }
    }
}
